package com.maserb.monitor.common;

import com.maserb.monitor.entity.*;
import com.maserb.monitor.enums.NodeTypeEnum;
import com.maserb.monitor.model.TreeItemModel;

import java.util.ArrayList;

public class TreeItemModelFactory {
    public static TreeItemModel createTreeItemModel(DeviceTreeEntity deviceTree) {
        String[] skins = {"area", "device", "part", "dynamicPoint", "staticPoint"};
        String iconSkin = skins[deviceTree.getNodeType() - 1];
        TreeItemModel item = new TreeItemModel(deviceTree.getId(), deviceTree.getName(), deviceTree.getCode(), deviceTree.getParentId(),
                true, true, iconSkin, deviceTree.getNodeType(),
                deviceTree.getDescription(), deviceTree.getCreateTime(), new ArrayList<TreeItemModel>());
        return item;
    }

    public static TreeItemModel createDeviceItem(TreeNodeEntity node, String parentId) {
        TreeItemModel item = new TreeItemModel(node.getId(), node.getName(),
                node.getCode(), parentId, true, true, "device",
                NodeTypeEnum.DEVICE.getValue(), node.getDescription(), node.getCreateTime(), new ArrayList<TreeItemModel>());

        return item;
    }

    public static TreeItemModel createAllItem(String id, String name, String code, String parentId, boolean open, boolean isParent,
                                              String description, String createTime) {
        TreeItemModel item = new TreeItemModel(id, name, code, parentId, open, isParent,
                "all", NodeTypeEnum.AREA.getValue(), description, createTime, new ArrayList<TreeItemModel>());
        return item;
    }

    public static TreeItemModel createDeviceItem(DeviceEntity device, String parentId) {
        TreeItemModel item = new TreeItemModel(device.getId(), device.getName(), device.getCode(), parentId,
                true, false, "device", NodeTypeEnum.DEVICE.getValue(),
                device.getDescription(), device.getCreateTime(), new ArrayList<TreeItemModel>());
        return item;
    }

    public static TreeItemModel createPartItem(PartEntity part, String parentId) {
        TreeItemModel item = new TreeItemModel(part.getId(), part.getName(), part.getCode(), parentId,
                true, false, "part", NodeTypeEnum.PART.getValue(),
                part.getDescription(), part.getCreateTime(), new ArrayList<TreeItemModel>());
        return item;
    }

    public static TreeItemModel createDynamicPointItem(DynamicPointEntity entity, String parentId) {
        TreeItemModel item = new TreeItemModel(entity.getId(), entity.getName(), entity.getCode(), parentId,
                true, false, "dynamicPoint", NodeTypeEnum.DYNAMICPOINT.getValue(),
                entity.getDescription(), entity.getCreateTime(), new ArrayList<TreeItemModel>());
        return item;
    }

    public static TreeItemModel createStaticPointItem(StaticPointEntity entity, String parentId) {
        TreeItemModel item = new TreeItemModel(entity.getId(), entity.getName(), entity.getCode(), parentId,
                true, false, "staticPoint", NodeTypeEnum.STATICPOINT.getValue(),
                entity.getDescription(), entity.getCreateTime(), new ArrayList<TreeItemModel>());
        return item;
    }

    public static TreeItemModel createAreaItem(AreaEntity entity, Object o) {
        TreeItemModel item = new TreeItemModel(entity.getId(), entity.getName(), null, null,
                true, false, "all", NodeTypeEnum.AREA.getValue(),
                entity.getDescription(), entity.getCreateTime(), new ArrayList<TreeItemModel>());
        return item;
    }
}
